package com.yaoxuguang.concurrence.mic;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence
 * @Description: Callable实现有返回值的多线程
 * @date 2018年12月14日11:36
 */
public class MyCallable implements Callable<String>{
    @Override
    public String call() throws Exception {
        int a = 1;
        int b = 2;
        System.out.printf("a和b的和是:%d %n",a+b);
        return "执行结果："+(a+b);
    }

    public static void main(String[] args) throws Exception {
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        MyCallable callable = new MyCallable();
        Future<String> future = executorService.submit(callable);
        System.out.println(future.get());
        executorService.shutdown();
    }
}
